﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Tx.OCC.UI.WPF
{
    /// <summary>
    /// OcctView.xaml 的交互逻辑
    /// </summary>
    public partial class OcctView : UserControl, IDisposable
    {
        public D3DViewer Viwer { get; private set; }
        public OcctView()
        {
            Viwer = new D3DViewer();
            var anImage = new ImageBrush(Viwer.Image);
            this.Background = anImage;
            this.MouseMove += g_MouseMove;
            this.MouseDown += g_MouseDown;
            this.MouseUp += g_MouseUp;
            this.MouseWheel += g_MouseWheel;
            this.SizeChanged += g_SizeChanged;
            //occtDrawGrid.HorizontalAlignment = HorizontalAlignment.Stretch;
        }

        void g_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Viwer.Resize(Convert.ToInt32(e.NewSize.Width), Convert.ToInt32(e.NewSize.Height));
        }

        void g_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Viwer.Viewer.OnMouseUp(this, e);
        }

        void g_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Viwer.Viewer.OnMouseDown(this, e);
        }

        void g_MouseMove(object sender, MouseEventArgs e)
        {
            Viwer.Viewer.OnMouseMove(this, e);
        }

        private void g_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            Viwer.Viewer.OnMouseWheel(this, e);
        }

        public void Dispose()
        {
            if (Viwer != null)
            {
                Viwer.Dispose();
                Viwer = null;
            }
        }
    }
}
